home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / fileops.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-29  |  1.9 KB  |  78 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10. #include <stdio.h>
  11. #include <fcntl.h>
  12. #include <sys/stat.h>
  13. #define  MAIN_PROG
  14. #include <comm.h>   /*     This file defines certain constants, and declares
  15.             some global variables used by the message passing
  16.             routines.  */
  17. #include <unistd.h>
  18.  
  19.  
  20. main(argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.   int ntasks, my_tid;
  25.   int fd, len, fd2, len2;
  26.   char buf[100001], *file;
  27.   struct stat stat_buf;
  28.  
  29.   file = "/nfs/pfs/divirs/jmsm/new/bin/sun4/nodemngr";
  30.   init_task(argv);    /* Initialization is required for all tasks in every
  31.              application */
  32.   pfs_debug=0;
  33.   my_tid = gettid(); 
  34.   if (my_tid == -1) {
  35.     io_printf(" task could not get its tid!", (char *)0);
  36.     exit(1);
  37.   }
  38.   
  39.   if ((fd = io_open(file, O_RDONLY, 0)) == -1) {
  40.     io_printf("Could not open file.", (char *)0);
  41.     exit(1);
  42.   }
  43.   io_printf("opened file for reading. fd= %d", fd, (char *)0);
  44.   
  45.   io_stat(file, &stat_buf);
  46.   
  47.   if (io_seek(fd, 1000, SEEK_CUR) == -1) 
  48.     io_printf("Could not seek file");
  49.  
  50.   if ((len = io_read(fd, buf, 1000, 0)) == -1) {
  51.     io_printf("Could not open file for reading: %s", p_err_string);
  52.     io_printf(" done.\n", my_tid, (char *)0 );
  53.     exit(1);
  54.   }  
  55.   
  56.   io_printf("read length: %d", len);
  57.   io_close(fd);
  58.   
  59.   fd2 = io_open("/nfs/pfs/divirs/jmsm/testfile", O_CREAT|O_WRONLY, 0x1B4);
  60.   if (fd2 == -1)  {
  61.     io_printf("could not open file for writing. %s", p_err_string);
  62.     io_printf(" done.\n", my_tid, (char *)0 );
  63.     exit(1);
  64.   }  
  65.  
  66.   io_printf("opened file for writing. fd = %d", fd2, (char *)0);
  67.   if ((len2 = io_write(fd2, buf, len)) == -1) {
  68.     io_printf("file write failed: %s", p_err_string);
  69.     exit(1);
  70.   }
  71.   else 
  72.     io_printf("write length: %d", len2);
  73.  
  74.   io_printf(" done.\n", my_tid, (char *)0 );
  75.   exit(0);
  76. }
  77.  
  78.